/**
 * This Class displays the list of the history events occured to a particular 
 * Case Record.
 */
package us.gaaoc.framework.webapp.backingbeans.judge;

import java.util.List;
import java.util.Map;

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import us.gaaoc.framework.model.CaseRecordHistory;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * @author Sukhada
 * Jul 6, 2006
 * GAJE_BibbCounty_1.0
 */
@SuppressWarnings("unchecked")
public class CaseRecordHistoryPage extends BaseBackingBean{
	
	/* **************** *
	 * Global Variables *
	 * **************** */
	
	/** Generated Serial Version UID */
	private static final long serialVersionUID = -5901792401661699267L;
	
	private DataModel historyDataTable;
	
	/**
	 * Constructor
	 */
	public CaseRecordHistoryPage() {
		this.loadData();
	}

	/**
	 * This method loads the history of the case record from the database.
	 *
	 */
	private void loadData() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		String caseUuid = (String) sessionMap.get("caseUuid");
		String courtUuid = (String) sessionMap.get("courtUuid");
		List<CaseRecordHistory> historyList = this.getModelFacade()
				.findHistoryByCaseRecordID(caseUuid, courtUuid);
		historyDataTable = new ListDataModel();
		historyDataTable.setWrappedData(historyList);
	}
	
	/**
	 * This method navigates user to the previous page.
	 * @return
	 */
	public String back() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		String fromPage = (String) sessionMap.get("from");
		sessionMap.remove("from");
		sessionMap.remove("caseUuid");

		if (fromPage.equalsIgnoreCase("ChildEnforcementCaseTypePage")) {
			return "gotoChildEnforcementCaseTypePage";
		} else if (fromPage.equalsIgnoreCase("ReceivedFilingPage")) {
			return "received";
		} else if (fromPage.equalsIgnoreCase("RejectedFilingPage")) {
			return "rejected";
		} else if (fromPage.equalsIgnoreCase("ImportedFilingPage")) {
			return "imported";
		} else if (fromPage.equalsIgnoreCase("DisposedFilingPage")) {
			return "disposed";
		} else if (fromPage.equalsIgnoreCase("ServedFilingPage")) {
			return "served";
		} else if (fromPage.equalsIgnoreCase("NonServedFilingPage")) {
			return "served";
		} else if (fromPage.equalsIgnoreCase("MainPage")) {
			return "mainPage";
		} else if (fromPage.equalsIgnoreCase("searchPage")){
			sessionMap.put("from","judgeMainPage");
			return "searchPage";
		}else
			return "";
	}

	/**
	 * @return Returns the historyDataTable.
	 */
	public DataModel getHistoryDataTable() {
		return this.historyDataTable;
	}

	/**
	 * @param historyDataTable The historyDataTable to set.
	 */
	public void setHistoryDataTable(DataModel historyDataTable) {
		this.historyDataTable = historyDataTable;
	}
}
